package com.khalil.kkadmin.common.util;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.iv.RandomIvGenerator;

public class JasyptTool {
    public static void encrypt(String password, String str) {
        StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor();
        /*配置文件中配置如下的算法*/
        standardPBEStringEncryptor.setAlgorithm("PBEWithMD5AndDES");
        standardPBEStringEncryptor.setIvGenerator(new RandomIvGenerator());
        /*配置文件中配置的password*/
        standardPBEStringEncryptor.setPassword(password);
        //加密
        String jasyptPasswordEN = standardPBEStringEncryptor.encrypt(str);
        //解密
        String jasyptPasswordDE = standardPBEStringEncryptor.decrypt(jasyptPasswordEN);
        System.out.println("加密后密码：" + jasyptPasswordEN);
        System.out.println("解密后密码：" + jasyptPasswordDE);
    }
}
